package seekting.demo2017.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.util.Log;

import com.seekting.logger.LoggerEnv;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import seekting.demo2017.AppEnv;

/**
 * Created by Administrator on 2017/9/5.
 */

public class LogcatActivity extends Activity {

    public static final boolean DEBUG = AppEnv.bAppdebug;
    public static final String TAG = "LogcatActivity";

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        recordLogcat(getApplication());


    }

    public static final String pattern = "yyyy-MM-dd-HH_mm_ss_SSS";
    public static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat(pattern);

    public static void recordLogcat(Context ctx) {
        String externalStorageDirectory = Environment.getExternalStorageDirectory().getPath();
        String path = externalStorageDirectory + "/paramount_log";
        String fileName = SIMPLE_DATE_FORMAT.format(new Date());
        LoggerEnv loggerEnv;
//        File file = new File("Logcat_" + fileName);
        File file = new File(path);
        if (DEBUG) {
            Log.d(TAG, "initLogger.externalStorageDirectory=" + path);
        }
        ArrayList cmdLine = new ArrayList();
        cmdLine.add("logcat");
        cmdLine.add("-d");
        cmdLine.add("-v");
        cmdLine.add("threadtime");
        cmdLine.add("-f");
        cmdLine.add("Logcat_" + fileName + ".txt");

        try {

            final Process process = Runtime.getRuntime().exec((String[]) cmdLine.toArray(new String[cmdLine.size()]), (String[]) null, file);
            (new Handler()).postDelayed(new Runnable() {
                public void run() {
                    process.destroy();
                }
            }, 1000L);
        } catch (Exception var4) {
            ;
        }

    }
}
